package com.lxp.project.quartz.service.impl;

import com.lxp.common.utils.StringUtils;
import com.lxp.project.quartz.domain.SysJobLog;
import com.lxp.project.quartz.mapper.SysJobLogMapper;
import com.lxp.project.quartz.service.ISysJobLogService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 定时任务调度日志信息 服务层
 *
 * @author lxp
 */
@Service
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService {
    /**
     * 获取quartz调度器日志的计划任务
     *
     * @param jobLog 调度日志信息
     * @return 调度任务日志集合
     */
    @Override
    public List<SysJobLog> selectJobLogList(SysJobLog jobLog) {
        QueryWrapper lqw = new QueryWrapper();
        if (StringUtils.isNotBlank(jobLog.getJobName())) {
            lqw.like(SysJobLog::getJobName, jobLog.getJobName());
        }
        if (StringUtils.isNotBlank(jobLog.getJobGroup())) {
            lqw.eq(SysJobLog::getJobGroup, jobLog.getJobGroup());
        }
        if (StringUtils.isNotBlank(jobLog.getStatus())) {
            lqw.eq(SysJobLog::getStatus, jobLog.getStatus());
        }
        if (StringUtils.isNotBlank(jobLog.getInvokeTarget())) {
            lqw.like(SysJobLog::getInvokeTarget, jobLog.getInvokeTarget());
        }
        if (jobLog.getBeginTime() != null) {
            lqw.ge(SysJobLog::getCreateTime, jobLog.getBeginTime());
        }
        if (jobLog.getEndTime() != null) {
            lqw.le(SysJobLog::getCreateTime, jobLog.getEndTime());
        }
        lqw.orderBy(SysJobLog::getCreateTime,false);
        return this.list(lqw);
    }

    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        mapper.cleanJobLog();
    }
}
